在 Python 中將行和列插入 Excel
IronXL for Python 提供程式化插入單個或多個行和列的能力,無需使用 Office Interop。
插入行
InsertRow 和 InsertRows 方法將新行添加到工作表中。 行會插入到指定索引位置之前。
插入列
使用 InsertColumn 和 InsertColumns 方法在指定索引位置之前添加一個或多個列。
所有索引位置均使用從零開始的索引。
from ironxl import *
# Load existing spreadsheet
workbook = WorkBook.Load("sample.xlsx")
worksheet = workbook.DefaultWorkSheet
# Add a row before row 1
worksheet.InsertRow(0)
# Insert multiple rows before row 4
worksheet.InsertRows(3, 3)
# Add a column before column A
worksheet.InsertColumn(0)
# Insert multiple columns before column F
worksheet.InsertColumns(5, 2)
# Save changes with added rows and columns
workbook.SaveAs("addRowAndColumn.xlsx")
IronXL for Python 提供程式化插入單個或多個行和列的能力,無需使用 Office Interop。
InsertRow 和 InsertRows 方法將新行添加到工作表中。 行會插入到指定索引位置之前。
使用 InsertColumn 和 InsertColumns 方法在指定索引位置之前添加一個或多個列。
所有索引位置均使用從零開始的索引。